package syntax

import scala.collection.mutable.ArrayBuffer

class CNonTerminal extends CCategory
{
    private val _name = getClass.getSimpleName
    private val _alternatives:ArrayBuffer[ArrayBuffer[CCategory]] = new ArrayBuffer[ArrayBuffer[CCategory]]()
    private val _priorities = ArrayBuffer[CNonTerminal]()

    override def name = _name
    def alternatives:Seq[Seq[CCategory]] = _alternatives
    def priorities:Seq[CNonTerminal] = _priorities

    protected def :=(category:CCategory):Unit = _alternatives += ArrayBuffer(category)

    protected def :=(chain:CChain):Unit = _alternatives += chain()

    protected def :=(alternatives:CAlternatives):Unit =
    {
        this._alternatives.clear()
        this._alternatives ++= alternatives() map (a => a())
    }

    protected def :>(nonTerminal:CNonTerminal) = _priorities += nonTerminal
}
